#ifndef __GSTREAMER_APPSRC_H__
#define __GSTREAMER_APPSRC_H__

#include <gst/gst.h>
#include <gst/app/gstappsrc.h>
#include <string>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <opencv2/opencv.hpp>

#define  LOG_GSTAPPSRC  "-- gst-appsrc-- "

/*
class gstAppsrc
{
public:
	_GstBus*     mBus;
	_GstElement* mPipeline;

	gstAppsrc();
	~gstAppsrc();

	//static gstAppsrc* Create( int v4l2_device=0, std::string target_ip, int target_port);
	gstAppsrc* Create( uint32_t width, uint32_t height, int v4l2_device, std::string target_ip, int target_port);
	bool Open(GstElement* pipeline, GstBus* bus);
	void start();

	static const uint32_t DefaultWidth  = 1280;
	static const uint32_t DefaultHeight = 720;

private:
	static void cb_need_data(GstElement *appsrc, guint unused_size, gpointer user_data);

	
	bool init_Pipeline();  //初始化pipeline
	bool buildLaunchStr();  //得到gat launch pipeline	
	void checkMsgBus(GstBus* bus); //message bus

	int   		mV4L2Device = 0;	// -1 for onboard, >=0 for V4L2 device
	std::string mTarget_ip = "127.0.0.1";
	int    		mPort = 5000;
	uint32_t 	mWidth;
	uint32_t 	mHeight;

//	cv::VideoCapture gstCapture;  //cv::videocapture 

// gstreamer相关
	_GstElement* mAppSrc;	
	std::string  mLaunchStr;		

};
*/



class gstAppsrc
{
public:

	_GstBus*     mBus;
	_GstElement* mPipeline;

	gstAppsrc();
	~gstAppsrc();
	bool Open(GstElement* pipeline, GstBus* bus);	
	//static gstAppsrc* Create( int v4l2_device=0, std::string target_ip, int target_port);
	gstAppsrc* Create( uint32_t width, uint32_t height, int v4l2_device, std::string target_ip, int target_port);	
	
private:
	static void cb_need_data(GstElement *appsrc, guint unused_size, gpointer user_data);
	bool buildLaunchStr();  //得到gat launch pipeline	
	bool init_Pipeline();  //初始化pipeline	
	void checkMsgBus(GstBus* bus); //message bus	

	// gstreamer相关
	_GstElement* mAppSrc;	
	std::string  mLaunchStr;
	
	int   		mV4L2Device = 0;	// -1 for onboard, >=0 for V4L2 device
	std::string mTarget_ip = "127.0.0.1";
	int    		mPort = 5000;
	uint32_t 	mWidth;
	uint32_t 	mHeight;			
};
#endif
